// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;

public class WinReqistry {
    public static String getSteamDirectory() {
        return readRegistry("HKEY_CURRENT_USER\\Software\\Valve\\Steam", "SteamPath");
    }

    public static final String readRegistry(String location, String key) {
        try {
            Process process = Runtime.getRuntime().exec("reg query \"" + location + "\" /v " + key);
            WinReqistry.StreamReader streamReader = new WinReqistry.StreamReader(process.getInputStream());
            streamReader.start();
            process.waitFor();
            streamReader.join();
            String string0 = streamReader.getResult();
            if (string0 != null && !string0.equals("")) {
                string0 = string0.substring(string0.indexOf("REG_SZ") + 7).trim();
                String[] string1 = string0.split("\t");
                return string1[string1.length - 1];
            } else {
                return null;
            }
        } catch (Exception exception) {
            return null;
        }
    }

    static class StreamReader extends Thread {
        private InputStream is;
        private StringWriter sw = new StringWriter();

        public StreamReader(InputStream inputStream) {
            this.is = inputStream;
        }

        public void run() {
            int _int;
            try {
                while ((_int = this.is.read()) != -1) {
                    this.sw.write(_int);
                }
            } catch (IOException iOException) {
            }
        }

        public String getResult() {
            return this.sw.toString();
        }
    }
}
